package org.example.admin.controller;

import org.example.admin.bo.RoleBO;
import org.example.admin.dto.RoleDto;
import org.example.admin.vo.RoleVo;
import org.example.core.utils.R;
import org.example.core.valid.group.AddGroup;
import org.example.core.valid.group.UpdateGroup;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import org.example.admin.service.RoleService;

import java.util.List;


/**
 * @author 小杰_cc
 * @version 1.0
 */
@RestController
@RequestMapping("/sys/backend/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    /**
     * 角色列表
     */
    @GetMapping("/list")
    public R<?> list(RoleDto roleDto){
        return R.ok(roleService.list(roleDto));
    }


    /**
     * 单个角色信息
     */
    @GetMapping("/{id}/detail")
    public R<?> detail(@PathVariable("id") Long id){
        RoleVo vo = roleService.detail(id);
        return R.ok(vo);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R<?> save(@Validated(value = {AddGroup.class}) @RequestBody RoleBO roleBO){
        return roleService.save(roleBO);
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public R<?> update(@Validated(value = {UpdateGroup.class}) @RequestBody RoleBO roleBO){
        roleService.update(roleBO);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R<?> delete(@RequestBody List<Long> ids){
        roleService.delete(ids);
        return R.ok();
    }

    /**
     * 获取所有
     */
    @GetMapping("/all")
    public R<?> allRole(){
        List<RoleVo> vos = roleService.allRole();
        return R.ok(vos);
    }

}
